<?php
class Penilaian_model extends MY_Model {
	
    function Penilaian_model (){
		parent::MY_Model();
        $this->load->database();
        $this->table_name = "penilaian";
        $this->table_fields = array('point_id', 'bap_id', 'perb_id', 'kary_id',
        	'kary_jbt_id', 'detachiev_id', 'point_tgl_aktif', 'point_count', 
        	'point_point');
    }
    
    function select_by_id($point_id){
    	if ($orderby) $this->db->order_by($orderby);
    	return $query = $this->db->get_where($this->table_name, array('point_id' => $id));
    }
    
    function count($kary_id, $kary_jbt_id, $detachiev_id){
    	$this->select_max('point_count');
    	$data = $this->get_where(array(
    		'kary_id'=>$kary_id,
    		'kary_jbt_id'=>$kary_jbt_id, 
    		'detachiev_id'=>$detachiev_id
    	));
    	
    	$data = $data->row();
    	return $data->point_count?$data->point_count:0;
    }
    
    function getByPeriode($karyID, $periodeStart=false, $periodeEnd=false, $limit=20, $offset=false, $orderby=false){
    	$where = "kary_id='$karyID'";
    	if ($periodeStart && $periodeEnd){
    		$where .= "AND DATE_FORMAT(point_tgl_aktif,'%Y-%m') BETWEEN 
    					DATE_FORMAT('$periodeStart','%Y-%m') AND 
    					DATE_FORMAT('$periodeEnd','%Y-%m')";
    	}
    	else if ($periodeStart){
    		$where .= "AND DATE_FORMAT(point_tgl_aktif,'%Y-%m') >= DATE_FORMAT('$periodeStart','%Y-%m')";
    	}
    	if ($orderby)$this->order_by($orderby);
    	return $this->get_where($where, $limit, $offset);
    }
}